#ifndef ACTIVE_H
#define ACTIVE_H

#include <boost/smart_ptr.hpp>
#include <boost/thread.hpp>
#include "ConcurrentQueue.h"


class Active: private boost::noncopyable
{ 
public:

  ///Base of all message types
  class Message 
  {
   public:
    virtual ~Message();
    virtual void Execute();
  }; 
  
typedef boost::shared_ptr<Message> MessagePtr;
typedef boost::shared_ptr <boost::thread_group> ThreadGrpPtr;

private:
  /// The dispatch loop: pump messages until done
  void Run();


public:
  /// Start everything up, using Run as the thread mainline
  Active(uint l_ParallelThread = 1); 
  /// Shut down: send sentinel and wait for queue to drain
  ~Active();
  /// Enqueue a message
  void Send( MessagePtr m );
  
private:
  // (suppress copying if in C++): implemented inheriting from boost::noncopyable
  // private data
  MessagePtr done;               // le sentinel  
  ConcurrentQueue< MessagePtr > mq;    // le queue  
  uint m_ParallelThreads;
  ThreadGrpPtr thdGroup;  
  
};

#endif // ACTIVE_H
